How To Verify Element is Enabled or Disabled

.
Verifying whether an element is enabled or Disable in Selenium webdriver

To verify whether the target element (Button, Checkbox, Dropdown, text box, Radio Button, Icons, etc ) is enabled or disabled use the isEnabled() Method.

Here, Element is disabled means the element is present on the webpage but not in editable mode. While working on a real-time project where we have to check whether the element is enabled or not. for example if some on automating the checkbox then first they have to check if checkbox is disabled in Selenium.


Disable and Enable Field In Selenium (eg. Checkbox, Button)


 isEnabled() Method 

In Selenium Webdriver isEnabled() method will verify and return a true value if the specified element is enabled. Otherwise, it will return a false value.

Syntax:
Syntax to verify whether the element on the webpage is enabled or disabled is given below.

 boolean FirstName= driver.findElement(By.id("fname")).isEnabled(); System.out.print(FirstName);


Selenium Code 

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
 
import org.openqa.selenium.chrome.ChromeDriver;
 
public class FacebookLogin {
 
     public static void main(String[] args) {
           // TODO Auto-generated method stub
           System.setProperty("webdriver.chrome.driver", "C:\\Software\\chromedriver.exe");
           WebDriver driver=new ChromeDriver();
           driver.get("https://www.facebook.com");
          
           //To verify that Element is Enabled
           Boolean nn =driver.findElement(By.xpath("//input[ @type=\"text\"]")).isEnabled();
     if(nn) {
           System.out.println("Yes ! Element is enabled");
     }
     else {
           System.out.println("NO ! Element is disabled");
     }
 
}
}



Hope !!! The above Tutorial on "How to check whether element is enabled or disabled in selenium helpful for you ...

Team,

QA acharya




How to check if element is disabled in Selenium Java

Post a Comment

0 Comments